<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>

<blockquote class="layui-elem-quote news_search">
    <form class="layui-form">
        <div>
            <div class="layui-inline">
                <!--<div class="layui-input-inline">
                    <input type="text" id="mname" value="" placeholder="消息关键词"
                        name="mname"  class="layui-input search_input">
                </div>-->
            </div>


            </div>
        </div>
        <div style="margin-top: 1%">
          <!--  <div class="layui-inline">
                <input type="text" id="creat"
                       class="layui-input userName" name="creat"
                       placeholder="时间" value="">
            </div>

            <a class="layui-btn search_btn" lay-submit="" data-type="search"
               lay-filter="search">查询</a>-->
            <!--<div class="layui-inline">
                <a class="layui-btn layui-btn-normal userAdd_btn">添加用户</a>
            </div>-->
            <div class="layui-inline">
                <a class="layui-btn layui-btn-danger batchDel">批量删除</a>
            </div>
          <!--  <div class="layui-inline">（支持模糊查询）</div>-->
        </div>
    </form>
</blockquote>

    <table id="history" lay-filter="test"></table>

<script type="text/html" id="barEdit">
   <!-- <a class="layui-btn layui-btn-xs" lay-event="edit">查看详情</a>-->
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


    <script th:src="@{/src/layui.js}"></script>
    <script>
        //layui基于组件(模块)开发的     ctrl+shift+f9  工具中重构代码
        layui.use(['table','laydate','jquery','layer'],function () {
            var table = layui.table;
            var laydate = layui.laydate;
            var $ = layui.jquery;
            var layer = layui.layer;
            table.render({
                elem:'#history',
                url:'/myhistory',
                width:1200,
                page:true,
                limit:5,
                limits:[5,10,15],
                cols:[
                    [
                        {field:'goodsHisId',type:'checkbox'},

                        {field:'goodsPrice',title:'出价',width:80},

                        {field:'goodsId',title:'商品编号',width:200},
                       /* {title:'查看详情',width:180,templet:'#mm'},*/
                        {field:'createTime',title:'出价时间',width:100},
                        {title:'操作',width:180,templet:'#barEdit'}

                    ]
                ],
                parseData:function (res) {
                    return {
                        "code":res.code==200?0:res.code,
                        "msg":res.message,
                        "count":res.data.total,
                        "data":res.data.list
                    }
                }
            })

            //日期控件
            var creat = laydate.render({
                elem:'#creat',
                max:'new Date()',

            });


            //搜索
            $(".search_btn").click(function () {
                table.reload('messages', {
                    url: '/selectMessage'
                    ,where: {
                        mname: $("#mname").val(),
                        creat:$("#creat").val(),

                    } //设定异步数据接口的额外参数

                });
            })
            //批量删除

            $(".batchDel").click(function () {
                var checkStatus = table.checkStatus("goods");
                //alert(checkStatus.data.length);
                var data = checkStatus.data;
                if(data.length == 0){
                    layer.msg("请选择数据",{icon:5,time:1000});
                    return ;
                }
                var keys = "";
                $.each(data,function (index,obj) {
                    keys += obj.goodsId+",";
                })
                keys = keys.substring(0,keys.length-1);
                layer.confirm('确认删除？',function (index) {
                    $.ajax({
                        url:'/deleteAllMyGoods/'+keys,
                        type:'delete',
                        dataType:'json',
                        success:function (res) {
                            if(res.code == 200){
                                layer.msg('删除成功',{icon:1},function () {
                                    location.reload();
                                })
                            }else{
                                layer.msg('删除失败',{icon:5});
                            }
                        }
                    })
                    layer.close(index);
                })

            })

            //添加

            
            table.on('tool(test)',function (obj) {
                var data = obj.data;//行数据
                var event = obj.event;
               /* if(event === 'edit'){
                    layer.open({
                        type:2,
                        title:'消息详情',
                        area:['500px','500px'],
                        content:'/detailMessage/'+data.typeId
                    });
                }else */if(event === 'del'){
                    layer.confirm('确认删除？',function (index) {
                        $.ajax({
                            url:'/deleteMyGoods/'+data.goodsId,
                            type:'delete',
                            dataType:'json',
                            success:function (res) {
                                if(res.code == 200){
                                    layer.msg('删除成功',{icon:1},function () {
                                        location.reload();
                                    })
                                }else{
                                    layer.msg('删除失败',{icon:5})
                                }
                            }
                        })

                        layer.close(index);
                    })
                }
            })

        })
    </script>



</body>
</html>